import paddlehub as hub
import cv2
import os

img_path = r'/Users/v/Downloads/00-02325/01-chapter-two'
path_list = [img_path + "/" + path for path in os.listdir(img_path)]
path_list = sorted(path_list)
print(path_list)

np_images =[cv2.imread(image_path) for image_path in path_list]

ocr = hub.Module(name="ch_pp-ocrv3", enable_mkldnn=False)       # mkldnn加速仅在CPU下有效
result = ocr.recognize_text(images=np_images)
# print(result)

# or 传递文件地址调用
#result = ocr.recognize_text(paths=[img_path])

fd = open("./ocr-result.txt", 'w')
for r in result:
    for c in r['data']:
        # print("content: ", c["text"])
        fd.write(c["text"] + "\n")

print("done")
fd.close()
